package com.baizhi.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.ShearCaptcha;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@RestController   //不用写resposeBody
public class CreateCaptcha {
    @RequestMapping("createCaptcha")
    public void createCaptcha(HttpServletResponse response,  HttpSession session) throws IOException {
        //定义图形验证码的长、宽、验证码字符数、干扰线宽度
        ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(300, 100, 4, 4);

        session.setAttribute("code",captcha.getCode());

        captcha.write(response.getOutputStream());
        response.getOutputStream().close();

    }
}
